// 封装权限管理用户相关接口
import request from '@/utils/request'
import type { ResponseUserList,UserAddParams,ResponseUserRoleList,UserRoleAssignParams} from '@/types/permission/user'

// 获取用户列表
export const getUserListAPI = (page: number,limit: number,username: string = '') => {
    return request.get<any,ResponseUserList>(`/admin/acl/user/${page}/${limit}?username=${username}`)
}

// 新增用户
export const addUserAPI = (data:UserAddParams) => {
    console.log(data);
    
    return request.post<any,any>(`/admin/acl/user/save`,{
        ...data
    })
}

// 更新用户
export const updateUserAPI = (data:UserAddParams) => {
    return request.put<any,any>(`/admin/acl/user/update`,{
        ...data
    })
}

// 删除用户
export const deleteUserAPI = (id:number | string) => {
    return request.delete<any,any>(`/admin/acl/user/remove/${id}`)
}

// 批量删除用户
export const batchDeleteUserAPI = (data:number[]) => {
    return request.delete<any,any>(`/admin/acl/user/batchRemove`,{
        data
    })
   }

// 根据用户获取角色列表
export const getRoleListByUserAPI = (adminId: string | number) => {
    return request.get<any,ResponseUserRoleList>(`/admin/acl/user/toAssign/${adminId}`)
}

// 根据用户分配角色
export const assignRoleAPI = (data:UserRoleAssignParams) => {
    return request.post<any,any>(`/admin/acl/user/doAssignRole`,{
        ...data
    })
}
